package com.anmong.parser.controller;

import com.anmong.parser.dto.FormatRequest;
import com.anmong.parser.dto.FormatResponse;
import com.anmong.parser.service.NovelFormattingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
public class FormatterController {

    private final NovelFormattingService formattingService;

    @Autowired
    public FormatterController(NovelFormattingService formattingService) {
        this.formattingService = formattingService;
    }

    @PostMapping("/format")
    public FormatResponse formatText(@RequestBody FormatRequest request) {
        String originalText = request.getText();
        String formattedText = formattingService.format(originalText);
        return new FormatResponse(formattedText);
    }
}